<template>
  <div>
    <el-card>
      <el-button size="mini" type="primary" @click="clickBatch">
        批量导入箱单发票
      </el-button>

      <el-button size="mini" type="primary" @click="resetInvoice">
        重置发票内容
      </el-button>
      <el-button size="mini" type="primary" @click="colDownload">
        下载装箱单
      </el-button>
      <el-button size="mini" type="primary" @click="setCache">
        缓存清单发票
      </el-button>
      <el-button size="mini" type="primary" @click="getCache">
        恢复清单发票缓存
      </el-button>
      <el-button size="mini" type="primary" @click="upLoadImg(0)">
        批量上传SKU图片
      </el-button>
      <el-button
        size="mini"
        v-if="isJapan"
        type="primary"
        @click="upLoadImg(1)"
      >
        批量上传售价截图
      </el-button>
      <el-button
        size="mini"
        v-if="isJapan"
        type="primary"
        @click="upLoadImg(2)"
      >
        批量上传收益截图
      </el-button>
      <el-button size="mini" type="primary" @click="shipmentBtn()">
        修改shipmentID、referenceID
      </el-button>
    </el-card>
    <el-card
      class="margin-top hot-table"
      v-loading.fullscreen.lock="pageLoading"
    >
      <div slot="header" class=" head-main flex justify-between align-center">
        <div>
          <span class="title-icon margin-right-sm">清关发票</span>
          <span class="margin-right">
            申报币种：
          </span>
          <span>
            <el-select
              v-model="channelFormLeft.declareValueCurrency"
              size="mini"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="(item, value) in currencyMap"
                :key="value"
                :label="item"
                :value="value"
              />
            </el-select>
          </span>
        </div>
        <el-button size="mini" type="success" @click="submitInfo"
          >保存清关发票和箱单</el-button
        >
      </div>

      <hot-table ref="hotTable" :settings="hotSettings" />

      <div class="padding text-center">
        <el-button type="success" @click.native="addEmptyData" size="mini">
          添加品名
        </el-button>
      </div>

      <!-- 批量导入箱单发票 -->
      <el-dialog
        title="批量导入箱单发票"
        :visible.sync="showUploadInvoice"
        width="66%"
        :before-close="handleClose"
        class="upload-Invoice-dialog"
      >
        <div class="flex align-center justify-around down-btn flex-wrap">
          <a href="/static/download/下载导入模板(适合FBA下单).xlsx">
            下载导入模板(适合FBA下单)
          </a>
          <a href="/static/download/下载导入模板(适合非FBA下单) .xlsx">
            下载导入模板(适合非FBA下单)
          </a>
          <a href="/static/download/下载导入模板(适合FBC下单).xlsx">
            下载导入模板(适合FBC下单)
          </a>
          <a href="/static/download/下载导入模板(适合非FBA，sku同款下单).xlsx">
            下载导入模板(适合非FBA，sku同款下单)
          </a>
          <a
            v-if="isJapan"
            href="/static/download/下载导入模板(适合日本线下单).xlsx"
          >
            下载导入模板(适合日本线下单)
          </a>
        </div>
        <div class="Invoice-dialog-tips-icon">
          <el-tooltip class="item" effect="light" placement="right">
            <div slot="content" style="line-htight:1.8">
              ①有新模板导入若多个SKU箱号相同，箱号，长，宽，高，重列请合并单元格；
              <br />
              <br />
              ②上传时请仔细检查模板数据,FBA需要填写Shipment ID，Reference ID；
              <br />
              <br />
              ③如果系统收入客户SKU信息，会自动补全部分缺损部分
            </div>
            <i class="el-icon-question icon-question text-yellow" />
          </el-tooltip>
        </div>
        <el-upload
          ref="upload"
          class="upload-demo"
          :limit="1"
          drag
          action="#"
          :auto-upload="false"
          :http-request="uploadFn"
          :file-list="fileList"
        >
          <i class="el-icon-upload" />
          <div class="el-upload__text">
            将文件拖到此处，或<em>点击上传</em>，支持多文件同时上传
            <br />
            <br />

            <span class="upload-tips">
              请您及时上传报关资料，如果不及时上传，系统会做扣货处理。
            </span>
          </div>
          <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
        </el-upload>
        <span slot="footer" class="dialog-footer">
          <el-button @click="showUploadInvoice = false">取 消</el-button>
          <el-button type="primary" @click="submitUpload"
            >上传到服务器</el-button
          >
        </span>
      </el-dialog>
      <!-- 上传图片 -->
      <UploadImg
        :show-upload-img.sync="showUploadImg"
        :rule-form.sync="ruleForm"
        :url="`/seaair/waybills/uploadImage`"
        @getImgUrl="getImgUrl"
      />
      <UploadImg2
        :show-upload-img.sync="showUploadImg2"
        :fnName="urlList[urlListIndex]"
        :waybillId="waybillId"
        :url="`/seaair/waybills/uploadImage`"
        @getImgUrl="getImgUrl2"
      />
    </el-card>

    <el-dialog
      :visible.sync="shipmentDialogVisible"
      width="66%"
      :before-close="handleClose"
      class="upload-Invoice-dialog"
      title="修改shipmentID、referenceID"
    >
      <el-row :gutter="0">
        <el-form
          ref="shipmentParasms"
          :model="shipmentData"
          :rules="shipmentRules"
          size="mini"
          label-width="120px"
          label-position="right"
        >
          <el-col :span="12">
            <el-form-item
              label-width="200px"
              label="原始Shipment ID:"
              prop="oldShipmentId"
            >
              <el-select
                v-model="shipmentData.oldShipmentId"
                placeholder="请选择下拉选择原始Shipment ID"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in oldShipmentIds"
                  :key="index"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item
              label-width="200px"
              label="新Shipment ID:"
              prop="newShipmentId"
            >
              <el-input
                v-model="shipmentData.newShipmentId"
                placeholder="请输入新Shipment ID"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label-width="200px"
              label="原始Reference ID:"
              prop="oldReferenceId"
            >
              <el-select
                v-model="shipmentData.oldReferenceId"
                placeholder="请选择原始Reference ID"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in oldReferenceIds"
                  :key="index"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item
              label-width="200px"
              label="新Reference ID:"
              prop="newReferenceId"
            >
              <el-input
                v-model="shipmentData.newReferenceId"
                placeholder="请输入新Reference ID"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
        <el-button type="primary" @click="shipmentConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { HotTable } from "@handsontable/vue";
import Handsontable from "handsontable";
import "handsontable/languages/zh-CN";
import globalData from "@/utils/config";
import { ajax } from "@/store/yg/common/utils";
import {
  selectSkuList,
  otherHeader,
  JapanLineHeader,
  colHeaders
} from "@/utils/invoice-table";
import { clone } from "@/utils/clone";
import {
  getSpanArr,
  isNoEmptyObject,
  checkRowsEmpty
} from "@/utils/invoice-table";
import UploadImg from "./uploadImg";
import UploadImg2 from "./uploadImg2";
import axios from "axios";
import { untransform } from "@/store/yg/common/uri";
import * as constant from "@/store/yg/common/constant";

export default {
  name: "Invoice",
  components: {
    HotTable,
    UploadImg,
    UploadImg2
  },
  props: {
    statusEnable: {
      type: Boolean,
      default: false
    },
    waybillId: {
      type: String,
      default: ""
    },
    publicData: {
      type: Object,
      default: function() {
        return {};
      }
    },
    channelFormLeft: {
      type: Object,
      default: function() {
        return {};
      }
    },
    invoiceInfoData: {
      type: Object,
      default: function() {
        return {
          oldPackingInfo: [],
          oldTableData: [],
          declareValueCurrency: "", // 币种
          tableData: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
        };
      }
    },
    japanLine: {
      type: Array,
      default: []
    },
    oldShipmentIds: {
      type: Array,
      default: []
    },
    oldReferenceIds: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      urlList: [
        "batchUploadSkuImage",
        "batchUploadSellpriceScreenshotImage",
        "batchUploadIncomeScreenshotImage"
      ],
      urlListIndex: 0,
      isJapan: 0,
      action: "",
      waybillAl: {},
      selectSkuList: [],
      fileList: [],
      timerFlag: false,
      timer: null,
      timer2: null,
      pageLoading: false,
      showUploadInvoice: false,
      showUploadImg: false,
      showUploadImg2: false,
      showImgDialog: false,
      dialogVisible: false,
      returnChange: false, // 阻止改变
      ruleForm: {
        coverFile: "",
        coverUrl: ""
      },
      currencyMap: this.publicData.currencyMap,
      skuUnitList: Object.values(this.publicData.skuUnitMap),
      listData: [],
      fbaRules: ["shipmentId", "referenceId"],
      rules: [
        "sku",
        "declareNameCn",
        "declareNameEn",
        "brand",
        "material",
        "purpose",
        "customsCode",
        "model",
        "num",
        "measurementUnit",
        "purchasingPrice",
        "sku",
        "declareValue",
        "imgUrl"
      ],
      jpRules: [
        "distributionMaterialCount",
        "productLotCount",
        "sellpriceScreenshot",
        "incomeScreenshot"
      ],
      shipmentDialogVisible: false,
      shipmentData: {},
      shipmentRules: {},

      params: {
        shipmentId: "Shipment ID",
        referenceId: "Reference ID",
        sku: "SKU",
        declareNameCn: "中文品名",
        declareNameEn: "英文品名",
        brand: "品牌",
        material: "材质",
        purpose: "用途",
        customsCode: "海关编码",
        model: "型号",
        num: "SKU个数",
        measurementUnit: "单位",
        purchasingPrice: "采购价格",
        declareValue: "申报价格",
        imgUrl: "SKU图片",
        fnSku: "FNSKU",
        distributionMaterialCount: "配送料",
        productLotCount: "出品手数料",
        sellpriceScreenshot: "售价截图",
        incomeScreenshot: "收益截图"
      },
      packingParams: {
        weight: "单箱毛重",
        length: "单箱长度",
        width: "单箱宽度",
        height: "单箱高度",
        startNumNo: "箱号",
        sku: "SKU",
        num: "SKU数量"
      },
      packingRules: ["startNumNo", "weight", "length", "width", "height"]
    };
  },

  computed: {
    autoHeight() {
      return this.invoiceInfoData &&
        this.invoiceInfoData.tableData &&
        this.invoiceInfoData.tableData.length > 16
        ? "420px"
        : "auto";
    },
    hotSettings() {
      return {
        currentRowClassName: "currentRow", // 为选中行添加类名，可以更改样式
        currentColClassName: "currentCol", // 为选中列添加类名
        rowHeaders: true, // 行表头
        // headerTooltips: true, // 鼠标划过头部时的提示文字
        data: this.invoiceInfoData.tableData,
        stretchH: "all", // 所有列宽小于表宽时,填充满整个表 all（所有列填充）/last（最后一列）/none(不填充)
        licenseKey: globalData.licensekey,
        // 定义表结构
        colHeaders: this.setHeader(),
        width: "100%",
        height: this.autoHeight,
        // TODO
        columns: this.buildColumns(this.isJapan, this.skuUnitList),
        tableClassName: ["first-class-name", "second-class-name"],
        language: "zh-CN",
        contextMenu: ["row_above", "row_below", "remove_row", "alignment"], // 开启右键菜单
        // 实例化之后
        // afterInit: () => {
        //   console.log('afterInit')
        // },
        // 改变前

        /**
         * @description:
         * @param {Number} row 数据第几行
         * @param {String} prop 参数名
         * @param {*} oldValue 该参数名 旧数据
         * @param {*} newValue 该参数名 新数据
         * @return {*}
         */
        beforeChange: async (changes, source) => {
          if (!changes) return;
          const [row, prop, oldValue, newValue] = changes[0];
          if (oldValue === newValue) {
            changes.length = 0;
            return;
          }

          const oldTableData = this.invoiceInfoData.oldTableData;
          console.log("oldTableData :>> ", oldTableData);
          if (oldTableData.length === 0) return;
          if (oldTableData[row] && oldTableData[row]["shipmentId"]) {
            const target = this.$parent.packingInfo.find(
              i => i.shipmentId === oldTableData[row]["shipmentId"]
            );

            if (prop === "num" && target) {
              for (const i of target.filterData) {
                if (
                  i.skuName === oldTableData[row]["sku"] &&
                  parseInt(i.packingNum) > parseInt(newValue)
                ) {
                  this.$message.error("当前修改的数量少于已装箱的数量");

                  this.$set(
                    this.invoiceInfoData.tableData[row],
                    prop,
                    oldValue
                  );
                  flag = false;
                  changes.length = 0;
                }
              }
            }
          }
        },
        // 改变后
        afterChange: async (changes, source) => {
          /**
           * 1.发票表格修改 该行2,12 存在既满足修改条件
           */

          if (!changes) return;

          // 解构赋值

          const oldData = this.invoiceInfoData.oldTableData;
          if (changes.length > 0) {
            // let delArr = [];
            for (const i of changes) {
              const [row, prop, oldValue, newValue] = i;
              // 判断 shk 、 num, 有旧数据，但是新数据为空
              if (
                (prop === "sku" && !newValue && oldValue && oldData[row].num) ||
                (prop === "num" && !newValue && oldValue && oldData[row].sku)
              ) {
                // delArr.push(oldData[row].sku);
                await this.delPackingData(oldData[row]);
              }
              this.afterChangeTable(i);
            }
            // console.log("delArr :>> ", delArr);
            // // 如果存在删除的数据
            // if (delArr.length === 0) {
            //   this.afterChangeTable(changes[0]);
            // }
          } else {
            this.afterChangeTable(changes[0]);
          }
        },
        // 单击之后
        afterOnCellMouseDown: (event, coords, TD) => {
          this.coords = coords;
        },
        /**
         * [一行或者多行移除后触发]
         * @param  {[number]} index        [起始行的可视索引]
         * @param  {[number]} amount       [删除行的数量]
         * @param  {[array]}  physicalRows [被删除行的数据组成的数组]
         * @param  {[string]} source       [触发的源]
         */
        afterRemoveRow: (index, amount, physicalRows, source) => {
          // this.IntegrateInvoiceData();
          if (this.invoiceInfoData.oldTableData[index]) {
            this.delPackingData(this.invoiceInfoData.oldTableData[index]);
          }
        },
        /**
         * [复制到表格后触发]
         * @param  {[array]} data   [复制的值]
         * @param  {[array]} coords [复制的目标区域坐标]
         */
        afterPaste: (data, coords) => {
          const oldTableData = this.invoiceInfoData.oldTableData;
          console.log("oldTableData :>> ", oldTableData);
          // return
          let cols = [2, 12];
          let prop = "";
          for (
            let index = coords[0].startCol;
            index <= coords[0].endCol;
            index++
          ) {
            if (cols.includes(index)) {
              prop = index === 2 ? "sku" : "num";
            }
          }

          setTimeout(async () => {
            const table = this.invoiceInfoData.tableData;
            const t = this.$refs.hotTable;
            for (
              let index = coords[0].startRow;
              index <= coords[0].endRow;
              index++
            ) {
              console.log("prop :>> ", prop);
              if (
                table[index].sku &&
                table[index].num &&
                prop &&
                table[index][prop] !== oldTableData[index][prop]
              ) {
                await this.afterChangeTable([
                  index,
                  prop,
                  oldTableData[index][prop],
                  table[index][prop]
                ]);
              }
            }
          });
        }
      };
    }
  },
  watch: {
    "channelFormLeft.purposeWarehouseType": {
      handler(newVal, oldVal) {
        // console.log('newVal purposeWarehouseType:>> ', newVal)
        this.changeChannelForm();
      }
    },
    invoiceInfoData: {
      handler(nVal) {
        console.log("nVal :>> ", nVal);
      }
    },
    selectSku: {
      handler(nVal) {
        // console.log('selectSku nVal :>> ', nVal)
      }
    }
  },
  created: function() {
    if (this.$route.query.isJapan) {
      this.isJapan = parseInt(this.$route.query.isJapan);
    }
    this.action =
      constant.API_SERVER +
      "/api/consume/upload?uri=" +
      untransform(this.$route.params.uri) +
      "&f=doImportLiquidationPackingByWaybill&type=blank";
  },
  mounted() {},
  beforeDestroy() {
    //清除定时器
    clearInterval(this.timer);
    console.log("beforeDestroy");
  },
  destroyed() {
    //清除定时器
    //clearInterval(this.timer);
    console.log("destroyed");
  },
  methods: {
    async shipmentConfirm() {
      var params = this.shipmentData;
      if (
        !this.shipmentData.newShipmentId &&
        this.shipmentData.oldReferenceId
      ) {
        this.$message.error(`新的shipmentId或者新的referenceID不允许同时为空`);
        return;
      }
      params.waybillId = this.waybillId;
      console.log("shipmentConfirm", params);
      const data = await ajax("updateShipmentAndRefenId", params);

      if (data.code === 200) {
        this.$message({
          type: "success",
          message: "保存成功！"
        });
        this.shipmentDialogVisible = false;
        location.reload();
      } else {
        this.$message.error(data.message || "保存失败");
      }
    },
    shipmentBtn() {
      this.shipmentDialogVisible = true;
    },
    upLoadImg(type) {
      this.urlListIndex = type;
      this.showUploadImg2 = true;
    },
    setCache() {
      let str = this.waybillId;

      sessionStorage.setItem(
        `tableInvoice-${str}`,
        JSON.stringify(this.invoiceInfoData.tableData)
      );
      sessionStorage.setItem(
        `tablePacking-${str}`,
        JSON.stringify(this.$parent.packingInfo)
      );
      this.$message.success("缓存成功");
    },
    getCache() {
      let str = this.waybillId;
      const data = sessionStorage.getItem(`tableInvoice-${str}`);
      const data2 = sessionStorage.getItem(`tablePacking-${str}`);

      if (data) {
        this.invoiceInfoData.tableData = JSON.parse(data);
        this.$message.success("恢复成功");
      } else {
        this.$message.warning("没有缓存数据");
      }

      if (data2) {
        this.$parent.packingInfo = JSON.parse(data2);
      }
    },
    resetPacking() {
      const tableData = this.invoiceInfoData.tableData.filter(x =>
        checkRowsEmpty(x)
      );

      if (tableData.length === 0) {
        this.$message.error("请填写发票数据！");
        return false;
      }
      const isFBA = this.channelFormLeft.purposeWarehouseType === 100;

      for (const [i, e] of tableData.entries()) {
        if (isFBA && !e.shipmentId) {
          this.$message.error(`请填写发票数据第${i + 1}，shipmentId`);
          return;
        }
        if (!e.sku) {
          this.$message.error(`请填写发票数据第${i + 1}行，sku`);
          return;
        }
        if (!e.num) {
          this.$message.error(`请填写发票数据第${i + 1}行，sku个数`);
          return;
        }
      }
      this.invoiceInfoData.oldPackingInfo = [];
      this.$parent.packingInfo = [];
      this.IntegrateInvoiceData();
    },
    async delPackingData(row) {
      console.log("删除数据 :>> ", row);
      console.log("this.invoiceInfoData :>> ", this.invoiceInfoData);
      const s = this.invoiceInfoData.tableData.find(
        x => x.shipmentId === row.shipmentId
      );
      const packingInfo = await clone(this.$parent.packingInfo);
      if (s) {
        console.log("部分删 :>> ");
        const target = packingInfo.find(x => x.shipmentId === row.shipmentId);
        console.log("target :>> ", target);
        if (!target) return;

        for (let index = target.filterData.length - 1; index >= 0; index--) {
          if (target.filterData[index].skuName === row.sku) {
            target.filterData.splice(index, 1);
          }
        }
        for (let index = target.tableData.length - 1; index >= 0; index--) {
          if (target.tableData[index].skuName === row.sku) {
            target.tableData.splice(index, 1);
          }
        }
        if (target.tableData.length > 0) {
          await getSpanArr(target);
        }
      } else {
        console.log("全删 :>> ");
        const index = packingInfo.findIndex(
          x => x.shipmentId === row.shipmentId
        );
        if (index > -1) {
          packingInfo.splice(index, 1);
        }
      }

      this.invoiceInfoData.oldPackingInfo = packingInfo;
      // 同步更新
      if (this.channelFormLeft.shippingWay !== "99") {
        this.$parent.packingInfo = packingInfo;
      }

      this.invoiceInfoData.oldTableData = await clone(
        this.invoiceInfoData.tableData
      );

      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
      console.log(
        "delPackingData this.$parent.invoiceInfo:>> ",
        this.$parent.invoiceInfo
      );
    },
    afterChangeTable(changes) {
      console.log("changes :>> ", changes);
      // 解构赋值
      const [row, prop, oldValue, newValue] = changes;
      const data = this.invoiceInfoData.tableData;
      const oldData = this.invoiceInfoData.oldTableData;

      // sku 填入
      if (prop === "sku" && this.selectSkuList.length > 0) {
        for (const i of this.selectSkuList) {
          if (i.sku === newValue) {
            // console.log('i :>> ', i)
            const t = clone(i);
            delete t.id;
            delete t.declareValue;
            if (!t.asin && t.salesConnection) {
              t.asin = t.salesConnection;
            }
            if (t.customsCodeList && t.customsCodeList.length > 0) {
              t.customsClearanceCode = t.customsCodeList[0].hscode;
              colHeaders[9] = `<span name="hscode">${
                this.publicData.customsCodeMap[
                  t.customsCodeList[0].customsCodeAreaManagementId
                ]
              }-清关编码</span>`;
            }
            if (
              t.customsDeclaredPriceList &&
              t.customsDeclaredPriceList.length > 0
            ) {
              t.declareValue = t.customsDeclaredPriceList[0].price;
            }

            delete t.customsCodeList;
            delete t.customsDeclaredPriceList;
            const s = Object.assign(data[row], t);
            this.$set(this.invoiceInfoData.tableData, row, s);
            this.$set(this.invoiceInfoData.tableData[row], "num", "");
          }
        }
      }

      const props = ["sku", "num", "shipmentId"];
      const props2 = ["declareNameCn", "declareNameEn"];
      console.log(
        "afterChangeTable this.$parent.invoiceInfo :>> ",
        this.$parent.invoiceInfo
      );
      console.log("this.invoiceInfoData :>> ", this.invoiceInfoData);
      // 判断修改的值
      if (oldValue !== newValue && props.includes(prop)) {
        // 存在SKU 数量，修改
        if (data[row].sku && data[row].num) {
          this.changeHandsontable({ row, prop, oldValue, newValue });
          console.log("this.invoiceInfoData :>> ", this.invoiceInfoData);
          console.log(
            "this.$parent.invoiceInfo :>> ",
            this.$parent.invoiceInfo
          );
        }
      }
      // 判断修改的值
      if (
        data[row].sku &&
        data[row].num &&
        oldValue !== newValue &&
        props2.includes(prop)
      ) {
        console.log("修改商品中英文名称 :>> ");
        this.changeGoodsName({ row, prop, oldValue, newValue });
      }
      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
      console.log(
        "afterChangeTable this.$parent.invoiceInfo :>> ",
        this.$parent.invoiceInfo
      );
    },

    checkInvoice() {
      const isFBA = this.channelFormLeft.purposeWarehouseType === 100;

      let rules = [...this.rules];
      if (isFBA) {
        rules = [...this.fbaRules, ...rules];
      }
      if (this.isJapan) {
        if (isFBA) {
          rules = [...rules, "fnSku", ...this.jpRules];
        } else {
          rules = [...rules, ...this.jpRules];
        }
      }

      if (!isNoEmptyObject(this.invoiceInfoData)) {
        this.$message.error("请填写发票数据！");
        return false;
      }

      if (this.invoiceInfoData.tableData.length === 0) {
        this.$message.error("请填写发票数据！");
        return false;
      }

      const tableData = this.invoiceInfoData.tableData.filter(x =>
        checkRowsEmpty(x)
      );
      const reg = new RegExp(
        "([\u4E00-\u9FFF]|[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b\uff01\u3010\u3011\uffe5])+",
        "g"
      );

      console.log("tableData :>> ", tableData);
      for (const [i, e] of tableData.entries()) {
        for (const j of rules) {
          // console.log('e[j] :>> ', e[j])
          if (
            isNoEmptyObject(e) &&
            j === "distributionMaterialCount" &&
            parseInt(e[j]) === 0
          ) {
            console.log("配送料为0 ");
          } else if (isNoEmptyObject(e) && !e[j]) {
            if (j === "declareValue" && this.isJapan) {
              this.$message.error(`请填写第${i + 1}行 必填数据 ASIN售价`);
            } else {
              this.$message.error(
                `请填写第${i + 1}行 必填数据 ${this.params[j]}`
              );
            }
            return false;
          }
          if (j === "declareNameEn" && reg.test(e[j])) {
            this.$message.error(
              `请填写第${i + 1}行 必填数据 英文品名 请勿包含中文字符`
            );
            return false;
          }

          if (
            (j === "num" ||
              j === "declareValue" ||
              j === "purchasingPrice" ||
              j === "distributionMaterialCount" ||
              j === "productLotCount") &&
            Object.prototype.toString.call(e[j]) !== "[object Number]"
          ) {
            this.$message.error(
              `第${i + 1}行 必填数据 ${this.params[j]},请填写正确数字`
            );
            return false;
          }

          // shipmentId
          if (
            this.channelFormLeft.purposeWarehouseType === 100 &&
            this.channelFormLeft.customerId != 3832 &&
            !reg.test(this.channelFormLeft.dispatchAddressCode)
          ) {
            if (
              isNoEmptyObject(e) &&
              j === "shipmentId" &&
              e[j] &&
              (e[j].indexOf("FBA") !== 0 || e[j].length !== 12)
            ) {
              this.$message.error(
                `Shipment ID 错误： FBA+(字母+数字组合)共12位`
              );
              return false;
            }
          }
          // measurementUnit

          if (j === "measurementUnit" && this.skuUnitList.includes(e[j])) {
            if (
              ["套", "包"].includes(e[j]) &&
              Object.prototype.toString.call(e.perSuitNum) !== "[object Number]"
            ) {
              this.$message.error(`第${i + 1}行 每套个数,请填写正确数字`);
              return false;
            } else if (["套", "包"].includes(e[j]) && !e.perSuitNum) {
              this.$message.error(
                `请填写第${i + 1}行每套个数,单位为套/包时,每套个数必填`
              );
              return false;
            }
          }
          if (j === "measurementUnit" && !this.skuUnitList.includes(e[j])) {
            this.$message.error(`第${i + 1}行,必填数据 单位，请选择正确的值`);
            return false;
          }
        }
        if (!this.channelFormLeft.isTaxFarming && !e.customsClearanceCode) {
          this.$message.error(`请填写第${i + 1}行 必填数据 清关编码`);
        }
      }
      return true;
    },

    checkPackingInfo(packingList, skuList) {
      // 校验箱单
      if (packingList) {
        console.log("packingList :>> ", packingList);
        if (packingList.length === 0) {
          this.$message.error(`请填写装箱单`);
          return false;
        }
        for (const [i, e] of packingList.entries()) {
          for (const j of this.packingRules) {
            if (isNoEmptyObject(e) && !e[j]) {
              this.$message.error(
                `请填写箱号${e.startNumNo}  ${this.packingParams[j]}`
              );
              return false;
            }
          }
          for (const k of e.packSkuList) {
            if (!k.sku) {
              this.$message.error(`请填写箱号${e.startNumNo} SKU`);
            }
            if (!k.num) {
              this.$message.error(`请填写箱号${e.startNumNo} SKU数量`);
            }
          }
        }
        console.log("skuList :>> ", skuList);
        for (const i of skuList) {
          if (parseInt(i.skuNum) !== parseInt(i.packingNum)) {
            this.$message.error(`${i.skuName} 装箱数量与发票填写个数不一致`);
            return false;
          }
        }
      }

      return true;
    },

    submitInfo() {
      // 箱单信息
      const plist = [];
      const skuList = [];
      if (!this.checkInvoice()) {
        return false;
      }
      console.log("this.$parent.packingInfo :>> ", this.$parent.packingInfo);
      for (const i of this.$parent.packingInfo) {
        console.log("i :>> ", i);
        for (const j of i.tableData) {
          const obj = {
            waybillId: "",
            shipmentId: j.shipmentId,
            startNumNo: j.cartonNo,
            endNumNo: j.cartonNo,
            length: j.length,
            width: j.width,
            height: j.height,
            weight: j.grossWeight,

            packSkuList: [
              {
                sku: j.skuName,
                declareNameCn: j.declareNameCn,
                declareNameEn: j.declareNameEn,
                num: j.skuNum
              }
            ]
          };
          plist.push(obj);
        }
        if (i.filterData) {
          console.log("i. :>> ", i.filterData);
          for (const k of i.filterData) {
            skuList.push(k);
          }
        }
        if (i.tableData.length > 0 && !i.filterData) {
          this.$message.error(
            "装箱单数据与发票数据匹配失败，请重置装箱单，或者重新导入箱单发票"
          );
          return;
        }
      }

      const packingList = plist.reduce((pVal, cVal) => {
        const target = pVal.find(x => x.startNumNo === cVal.startNumNo);
        if (target) {
          // 相同sku 合并数量
          target.packSkuList = [...target.packSkuList, ...cVal.packSkuList];
        } else {
          pVal.push(cVal);
        }
        return pVal;
      }, []);
      if (this.channelFormLeft.shippingWay !== "99") {
        if (!this.checkPackingInfo(packingList, skuList)) {
          return false;
        }
        // if (this.channelFormLeft.inStockTotalPackages) {
        // 件数需要 与装箱数相等  快递除外 待出库之前 取入库件数
        //   if (
        //     this.channelFormLeft.inStockTotalPackages !== packingList.length
        //   ) {
        //     this.$message.error("入库件数和装箱单数量不匹配");
        //     return;
        //   }
        // } else {
        // 件数需要 与装箱数相等  快递除外 待出库之前 取客户预报数
        console.log("packingList :>> ", packingList);
        console.log(
          "this.channelFormLeft.customerTotalPackages :>> ",
          this.channelFormLeft.customerTotalPackages
        );
        if (this.channelFormLeft.customerTotalPackages !== packingList.length) {
          this.$message.error("客户下单件数和装箱单数量不匹配");
          return;
        }
        // }
      }

      this.pageLoading = true;
      const invoiceList = [];

      if (this.invoiceInfoData.tableData) {
        const t = clone(this.invoiceInfoData.tableData);
        for (const i of t) {
          if (i.sku) {
            i.imgUrl = i.imgUrl.replace(constant.FILE_SERVER, "");

            if (i.incomeScreenshot) {
              i.incomeScreenshot = i.incomeScreenshot.replace(
                constant.FILE_SERVER,
                ""
              );
            }
            // if (i.isCharged === "是") {
            //   i.isCharged = 1;
            // } else {
            //   i.isCharged = 0;
            // }

            invoiceList.push(i);
          }
        }
      }

      const params = {
        declareValueCurrency: this.channelFormLeft.declareValueCurrency,
        id: this.waybillId,
        liquidationInvoiceSet: invoiceList,
        purposeWarehouseType: this.channelFormLeft.purposeWarehouseType
      };
      if (this.channelFormLeft.shippingWay !== "99") {
        params.packingListSet = packingList;
      }
      console.log("params :>> ", params);
      // return;
      this.saveInfo(params);
    },

    async saveInfo(params) {
      const data = await ajax("saveLiquidationPackingData", params);
      this.pageLoading = false;
      if (data.code === 200) {
        this.$message({
          type: "success",
          message: "保存成功！"
        });
      } else {
        this.$message.error(data.message || "保存失败");
      }
    },

    async colDownload() {
      console.log("waybillId", this.waybillId);
      const data = await ajax("exportLiquidationPackingErp", {
        waybillId: this.waybillId
      });
      if (data.path) {
        window.open(constant.FILE_SERVER + data.path);
      } else {
        this.$message.error(data.errorMesage || "下载失败");
      }
    },

    clickBatch() {
      if (!this.channelFormLeft.inStockChannel) {
        this.$message.error("请先选择渠道！");
        return;
      }
      this.fileList = [];
      this.showUploadInvoice = true;
    },
    getImgUrl(url) {
      console.log("url :>> ", url);
      console.log("this.coords.col :>> ", this.coords.col);
      const row = this.invoiceInfoData.tableData[this.coords.row];
      let n = "imgUrl";
      switch (this.coords.col) {
        case 18:
          n = "imgUrl";
          break;
        case 21:
          n = "imgUrl";
          break;
        case 22:
          n = "sellpriceScreenshot";
          break;
        case 23:
          n = "incomeScreenshot";
          break;
      }
      console.log("n :>> ", n);
      this.$delete(row, n);
      this.$set(row, n, url);
      console.log(
        " this.invoiceInfoData.tableData[this.coords.row];:>> ",
        this.invoiceInfoData.tableData[this.coords.row]
      );
      // this.$set(row, n, constant.FILE_SERVER + url);

      if (this.ruleForm.coverUrl) {
        const tbody = this.$refs.hotTable.$el.children[0].children[0]
          .children[0].children[0].children[0].children[2].children[
          this.coords.row
        ].children[this.coords.col + 1].children[0];

        tbody.src = constant.FILE_SERVER + url;
        console.log("this.$refs.hotTable :>> ", tbody);
      }
      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
      console.log(
        "this.getImgUrl this.$parent.invoiceInfo:>> ",
        this.$parent.invoiceInfo
      );
    },
    // 批量上传图片数据 加入table
    getImgUrl2(data) {
      console.log("getImgUrl2 :>> ", data);
      for (const i of this.invoiceInfoData.tableData) {
        console.log("i.sku :>> ", i.sku);
        console.log("data[i.sku] :>> ", data[i.sku]);
        if (i.sku && data[i.sku]) {
          let key = "";
          switch (this.urlListIndex) {
            case 0:
              key = "imgUrl";
              break;
            case 1:
              key = "sellpriceScreenshot";

              break;
            case 2:
              key = "incomeScreenshot";
              break;
          }
          this.$delete(i, key);
          this.$set(i, key, data[i.sku]);
        }
      }
      console.log(
        "this.invoiceInfoData.tableData :>> ",
        this.invoiceInfoData.tableData
      );
      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
    },
    submitUpload() {
      this.$refs.upload.submit();
    },
    batchUoload() {
      // console.log('this.channelFormLeft :>> ', this.channelFormLeft)
      // if()
      // this.showUploadInvoice = !this.showUploadInvoice
    },
    async uploadFn(params) {
      // console.log('params', params)
      // console.log('params', params.file.type)
      const isEXCEL =
        params.file.type === "application/vnd.ms-excel" ||
        params.file.type ===
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      if (!isEXCEL) {
        this.$message.error("上传文件只能是EXCEL文件!");
        return false;
      }
      // 通过 FormData 对象上传文件
      var formData = new FormData();
      formData.append("countryId", this.channelFormLeft.countryId);
      formData.append(
        "purposeWarehouseType",
        this.channelFormLeft.purposeWarehouseType
      );
      formData.append("waybillId", this.waybillId);

      // TODO 修改
      formData.append("items[]", params.file);
      axios({
        method: "post",
        url: this.action,
        data: formData
      })
        .then(response => {
          response = response.data;
          console.log(response);
          if (response.code != 200) {
            var errorMassage = "";
            if (response.message != null && response.message != "") {
              errorMassage = response.message;
            }
            this.$notify.error({
              title: "错误",
              message: "上传失败!" + errorMassage
            });
          } else {
            const data = response.data;
            this.fileList = [];
            if (data.error) {
              this.$message.error(data.error);
              return;
            }
            if (data.declareValueCurrency) {
              // 同步发票
              if (!this.isJapan) {
                this.invoiceInfoData.declareValueCurrency =
                  data.declareValueCurrency;
              }
              this.invoiceInfoData.tableData = data.liquidationInvoices;
              this.invoiceInfoData.oldTableData = clone(
                data.liquidationInvoices
              );

              this.$parent.invoiceInfo = clone(this.invoiceInfoData);
              console.log(
                "uploadFn this.$parent.invoiceInfo :>> ",
                this.$parent.invoiceInfo
              );
              // 同步箱单
              if (this.channelFormLeft.shippingWay !== "99") {
                if (data.packingListmMap) {
                  // 存在箱单信息
                  console.log("上传信息存在箱单信息");
                  this.IntegratePackingData(data.packingListmMap);
                } else {
                  // 不存在箱单信息 根据发票生成
                  // console.log('上传信息不存在箱单信息')
                  this.IntegrateInvoiceData();
                }
              }
              this.$message({
                message: "导入成功！",
                type: "success"
              });

              this.showUploadInvoice = false;
            }
          }
        })
        .catch(error => {
          console.log(error);
          this.$notify.error({
            title: "错误",
            message: "上传失败!"
          });
        });
    },

    // 整合数据
    IntegrateData() {
      const isFBA = this.channelFormLeft["purposeWarehouseType"] === 100;
      const isVip = this.channelFormLeft.customerId === 3832;
      // 新数据
      const newArr = [];

      this.invoiceInfoData.tableData.forEach((j, index) => {
        if (this.isNoEmptyObject(j) && j.sku && j.num) {
          j.shipmentId = j.shipmentId ? j.shipmentId.trim() : "";
          const obj = {
            shipmentId: j.shipmentId,
            show: true,
            filterData: [
              {
                skuName: j.sku,
                declareNameCn: j.declareNameCn || "",
                declareNameEn: j.declareNameEn || "",
                skuNum: j.num,
                packingNum: "0",
                inputNum: "0"
              }
            ],
            startBoxNo: null,
            endBoxNo: null,
            show: true,
            oldRule: "U000001", // 箱规旧值
            rule: "U000001", // 默认箱规
            grossWeight: "", // 毛重
            length: "",
            width: "",
            height: "",
            tableData: [],
            spanArr: [],
            pos: 0
          };
          newArr.push(obj);
        }
      });

      if (newArr.length === 0) return [];

      const newArray = isFBA ? newArr.filter(i => i.shipmentId !== "") : newArr;
      // console.log('newArray :>> ', newArray)
      //
      const filteredData = newArray.reduce((acc, cur, index, arr) => {
        const target = acc.find(e => e.shipmentId === cur.shipmentId);
        // 判断是否存在相同shipmentId数据
        if (target) {
          cur.filterData.reduce((pVal, cVal) => {
            const target1 = pVal.find(x => x.skuName === cVal.skuName);
            if (target1) {
              // 相同sku 合并数量
              target1.skuNum += parseInt(cVal.skuNum);
            } else {
              pVal.push(cVal);
            }
            return pVal;
          }, target.filterData);
        } else {
          acc.push(cur);
        }

        return acc;
      }, []);

      // console.log('filteredData 11111:>> ', filteredData)
      console.log("this.$p :>> ", this.$parent.invoiceInfo);
      return filteredData;
    },
    /**
     * @description: 根据表单生成对应箱单
     * @param {Number} row 数据第几行
     * @param {String} prop 参数名
     * @param {*} oldValue 该参数名 旧数据
     * @param {*} newValue 该参数名 新数据
     * @param {Boolean} changeFba 改变仓库类型
     */
    async changeHandsontable({
      row,
      prop,
      oldValue,
      newValue,
      changeFba = false
    }) {
      /** 直接修改表格
       * 1.发票表格修改shipment ID ,判断是否已存在该行数据
       * 2.存在该行数据，保持其他数据，修改该数据
       * 3.不存在该行数据，并且满足生成条件，生成数据
       * 4.判断条件  oldValue === undefined && props.includes(prop)
       */
      console.log("修改表格 :>> ", "修改表格");
      console.log("this.$parent.invoiceInfo11 :>> ", this.$parent.invoiceInfo);
      const filteredData = await this.IntegrateData();
      console.log("this.$parent.invoiceInfo :>> ", this.$parent.invoiceInfo);
      // console.log(
      //   '%cchangeHandsontabl-filteredData: ',
      //   'color: #fff; background: #000;',
      //   filteredData
      // )
      // return
      const props = ["sku", "num"];
      const params = {
        filteredData,
        row,
        prop
      };
      // console.log('this.invoiceInfoData 401 :>> ', this.invoiceInfoData)
      // console.log('oldValue :>> ', oldValue)
      // 满足 shipmentId sku num 并且其中一项之前为空 => 新增数据
      if (this.channelFormLeft["purposeWarehouseType"] === 100) {
        props.push("shipmentId");
      }
      if (prop && props.includes(prop) && !oldValue && newValue) {
        this.increasePackingData(params);
      } else {
        this.changePackingData(params);
      }
    },
    // 新增数据
    async increasePackingData(params) {
      console.log("新增数据", params);
      const oldData = this.$parent.invoiceInfo.oldPackingInfo;
      let packingInfo = [];
      const filteredData = clone(params.filteredData);

      // 将旧值 还原
      oldData.reduce((pVal, cVal) => {
        const targetShipmentId = pVal.find(
          x => x.shipmentId === cVal.shipmentId
        );
        if (targetShipmentId) {
          cVal.filterData.reduce((pVal, cVal) => {
            const target1 = pVal.find(x => x.skuName === cVal.skuName);
            if (target1) {
              // 接收已装箱值，其他不改变
              target1.packingNum = cVal.packingNum;
            } else {
              pVal.push(cVal);
            }
            return pVal;
          }, targetShipmentId.filterData);

          Object.assign(targetShipmentId, {
            spanArr: cVal.spanArr,
            tableData: cVal.tableData,
            rule: cVal.rule
          });
        } else {
          pVal.push(cVal);
        }
        return pVal;
      }, filteredData);
      packingInfo = await clone(filteredData);
      console.log("packingInfo :>> ", packingInfo);
      this.invoiceInfoData.oldPackingInfo = packingInfo;
      // 同步更新
      if (this.channelFormLeft.shippingWay !== "99") {
        this.$parent.packingInfo = packingInfo;
      }

      this.invoiceInfoData.oldTableData = await clone(
        this.invoiceInfoData.tableData
      );

      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
      console.log(
        "increasePackingData this.$parent.invoiceInfo:>> ",
        this.$parent.invoiceInfo
      );
    },
    // 修改数据
    async changePackingData(params) {
      console.log("this.$parent.invoiceInfo :>> ", this.$parent.invoiceInfo);
      console.log("修改数据", params);
      let filteredData = clone(params.filteredData);
      let packingInfo = [];
      const oldData = this.$parent.invoiceInfo.oldPackingInfo;
      console.log("修改数据 oldData :>> ", this.$parent.invoiceInfo);
      // 旧数据为空
      if (oldData.length === 0) {
        console.log("旧数据为空");
        this.increasePackingData(params);
        return;
      }

      const oldTarget = oldData.find(
        i =>
          i.shipmentId ===
          this.invoiceInfoData.oldTableData[params.row].shipmentId
      );

      let newTarget = filteredData.find(
        i =>
          i.shipmentId === this.invoiceInfoData.tableData[params.row].shipmentId
      );
      // 获取目标下标
      const index = filteredData
        .map(item => item.shipmentId)
        .indexOf(this.invoiceInfoData.tableData[params.row].shipmentId);

      const oldSid = oldTarget.shipmentId;

      const oldSkuName = this.invoiceInfoData.oldTableData[params.row]
        ? this.invoiceInfoData.oldTableData[params.row].sku
        : "";
      const newSkuName = this.invoiceInfoData.tableData[params.row]
        ? this.invoiceInfoData.tableData[params.row].sku
        : "";
      // 修改shipmentID 且旧数据存在修改后的id
      if (params.prop === "shipmentId") {
        filteredData = await this.changeShipmentID({
          oldSid,
          newTarget,
          oldTarget,
          oldSkuName,
          oldData,
          filteredData: filteredData
        });

        // 还原非修改目标数据
        for (const [i, e] of filteredData.entries()) {
          if (
            e.shipmentId !== oldSid &&
            e.shipmentId !== newTarget.shipmentId
          ) {
            const t = oldData.find(x => x.shipmentId === e.shipmentId);
            if (t) {
              filteredData.splice(i, 1, t);
            }
          }
        }
      } else if (params.prop === "sku") {
        newTarget = await this.changeSkuName({
          newTarget,
          oldTarget,
          oldSkuName,
          row: params.row,
          newSkuName,
          oldData
        });
      } else if (params.prop === "num") {
        await this.changePackingNum(oldTarget.filterData, newTarget.filterData);
        newTarget.spanArr = oldTarget.spanArr;
        newTarget.tableData = oldTarget.tableData;
        newTarget.rule = oldTarget.rule;
      } else if (params.prop === "declareNameCn") {
        const oldName = this.invoiceInfoData.oldTableData[params.row]
          .declareNameCn;
        const name = this.invoiceInfoData.tableData[params.row].declareNameCn;
        for (const i of oldTarget.filterData) {
          if (
            oldName &&
            i.declareNameCn === oldName &&
            i.skuName === newSkuName
          ) {
            i.declareNameCn = name;
          } else if (i.skuName === newSkuName) {
            i.declareNameCn = name;
          }
        }

        for (const i of oldTarget.tableData) {
          if (
            oldName &&
            i.declareNameCn === oldName &&
            i.skuName === newSkuName
          ) {
            i.declareNameCn = name;
          } else if (i.skuName === newSkuName) {
            i.declareNameCn = name;
          }
        }

        newTarget.filterData = oldTarget.filterData;
        newTarget.tableData = oldTarget.tableData;
      } else {
        newTarget = oldTarget;
      }

      let obj = newTarget;
      if (newTarget.tableData.length > 0) {
        obj = await getSpanArr(newTarget);
      }

      filteredData.splice(index, 1, obj);

      packingInfo = filteredData;

      console.log(
        "%c 修改数据-packingInfo: ",
        "color: MidnightBlue; background: Aquamarine;",
        filteredData
      );

      this.invoiceInfoData.oldPackingInfo = await clone(packingInfo);
      // 同步更新
      if (this.channelFormLeft.shippingWay !== "99") {
        this.$parent.packingInfo = packingInfo;
      }

      this.invoiceInfoData.oldTableData = await clone(
        this.invoiceInfoData.tableData
      );
      this.$parent.invoiceInfo = clone(this.invoiceInfoData);
      console.log(
        "changePackingData this.$parent.invoiceInfo :>> ",
        this.$parent.invoiceInfo
      );
    },

    // 通过上传文件导入的发票数据
    async IntegrateInvoiceData() {
      const filteredData = await this.IntegrateData();

      const params = {
        filteredData
      };
      if (filteredData.length === 0) {
        // 发票数据为空

        this.$parent.packingInfo = [];
      } else {
        this.increasePackingData(params);
      }
    },

    // 处理返回的数组
    async processingArrInfo(data) {
      const isVip = this.channelFormLeft.customerId === 3832;
      const packingInfo = [];
      let sid = "";
      if (isVip) {
        sid = data[0].startNumNo.slice(0, 9);
      } else {
        sid = data[0].startNumNo.slice(0, data[0].startNumNo.lastIndexOf("U"));
      }
      const obj = {
        shipmentId: sid,
        tableData: [],
        show: true
      };
      for (const i of data) {
        // for (const j of data[i]) {
        const l = i.startNumNo.slice(i.startNumNo.lastIndexOf("U")).length;
        // console.log('l :>> ', l)
        switch (l) {
          case 4:
            obj.rule = "U001";
            break;
          case 5:
            obj.rule = "U0001";
            break;
          case 6:
            obj.rule = "U00001";
            break;
          case 7:
            obj.rule = "U000001";
            break;
          default:
            obj.rule = "U0001";
            break;
        }
        if (i.packSkuList.length > 0) {
          for (const k of i.packSkuList) {
            obj.tableData.push({
              cartonNo: i.startNumNo,
              declareNameCn: k.declareNameCn,
              declareNameEn: k.declareNameEn,
              grossWeight: i.weight,
              height: i.height,
              length: i.length,
              shipmentId:
                data[0].startNumNo.slice(
                  0,
                  data[0].startNumNo.lastIndexOf("U")
                ) || "",
              skuName: k.sku,
              skuNum: k.num,
              width: i.width
            });
          }
        } else {
          obj.tableData.push({
            cartonNo: i.startNumNo,
            declareNameCn: "",
            declareNameEn: "",
            grossWeight: i.weight,
            height: i.height,
            length: i.length,
            shipmentId: i.shipmentId || "",
            skuName: "",
            skuNum: "",
            width: i.width
          });
        }
      }

      if (obj.tableData.length > 0) {
        await getSpanArr(obj, isVip);
      }
      console.log("obj.tableData :>> ", obj);
      packingInfo.push(obj);

      // console.log('packingInfo :>> ', packingInfo)
      return packingInfo;
    },
    // 处理返回的对象
    async processingObjInfo(data) {
      console.log("data :>> ", data);
      const isVip = this.channelFormLeft.customerId === 3832;
      const packingInfo = [];
      for (const i in data) {
        console.log("i :>> ", i);
        const obj = {
          shipmentId: i,
          tableData: [],
          show: true
        };
        for (const j of data[i]) {
          const l = j.startNumNo.slice(j.startNumNo.lastIndexOf("U")).length;
          switch (l) {
            case 4:
              obj.rule = "U001";
              break;
            case 5:
              obj.rule = "U0001";
              break;
            case 6:
              obj.rule = "U00001";
              break;
            case 7:
              obj.rule = "U000001";
              break;
          }

          for (const k of j.packSkuList) {
            obj.tableData.push({
              cartonNo: j.startNumNo,
              declareNameCn: k.declareNameCn,
              declareNameEn: k.declareNameEn,
              grossWeight: j.weight,
              height: j.height,
              length: j.length,
              shipmentId: i,
              skuName: k.sku,
              skuNum: k.num,
              width: j.width
            });
          }
        }
        await getSpanArr(obj, isVip);
        packingInfo.push(obj);
      }
      console.log("packingInfo :>> ", packingInfo);
      return packingInfo;
    },

    // 通过上传文件导入的箱单数据
    async IntegratePackingData(waybill) {
      console.log("waybill :>> ", waybill);
      if (!waybill) return;
      const data = waybill;
      // this.waybillAll = waybill.data;
      // console.log('data :>> ', data)
      let packingInfo = [];
      if (Object.prototype.toString.call(data) === "[object Array]") {
        packingInfo = await this.processingArrInfo(data);
      } else if (Object.prototype.toString.call(data) === "[object Object]") {
        console.log("value是对象");
        packingInfo = await this.processingObjInfo(data);
      }

      // console.log('packingInfo :>> ', packingInfo)
      const filteredData = await this.IntegrateData();
      for (const i of filteredData) {
        for (const j of packingInfo) {
          if (i.shipmentId === j.shipmentId) {
            j.filterData = i.filterData;
            for (const k of j.filterData) {
              let num = 0;
              for (const u of j.tableData) {
                if (u.skuName === k.skuName) {
                  num += parseInt(u.skuNum);
                }
              }
              k.packingNum = num;
            }
          }
        }
      }
      console.log(">>>>>>", packingInfo);
      this.$parent.packingInfo = clone(packingInfo);
      this.$parent.invoiceInfo.oldPackingInfo = clone(packingInfo);
      this.invoiceInfoData.oldPackingInfo = clone(packingInfo);
    },
    /**
     * @description:
     * @param {*} oldSid 修改前的sid
     * @param {*} newTarget 修改后的目标数据
     * @param {*} oldTarget 修改前的目标数据
     * @param {*} oldSkuName 修改前的sku
     * @param {*} oldData 修改前的装箱单数据
     * @param {*} filteredData
     * @return {*}
     */
    async changeShipmentID({
      oldSid,
      newTarget,
      oldTarget,
      oldSkuName,
      oldData,
      filteredData
    }) {
      // 获取 旧SID 在修改前Table数据列表
      const oldSidList = this.invoiceInfoData.oldTableData.filter(
        i => i.shipmentId === oldTarget.shipmentId
      );
      // 获取新SID 在修改前Table数据列表

      const newSidList = this.invoiceInfoData.oldTableData.filter(
        i => i.shipmentId === newTarget.shipmentId
      );

      // 旧shipmentId的packing 数据
      const oldPacking_oldSid = oldData.find(i => i.shipmentId === oldSid);
      const oldPacking_newSid = oldData.find(
        i => i.shipmentId === newTarget.shipmentId
      );

      // 新数据
      const newPacking_oldSid = filteredData.find(i => i.shipmentId === oldSid);
      const newPacking_newSid = filteredData.find(
        i => i.shipmentId === newTarget.shipmentId
      );
      console.log("newPacking_oldSid :>> ", newPacking_oldSid);
      console.log("newPacking_newSid :>> ", newPacking_newSid);

      // 大于1 && 大于0,证明改之前存在同shipmentID 数据/
      if (oldSidList.length > 1 && newSidList.length > 0) {
        console.log(
          "-----------修改前存在新SID数据，修改后存在旧SID数据----------"
        );
        // TODO 区分 相同shipmentID，相同skuName 的已装箱tableData 的分离
        newPacking_oldSid.tableData.push(
          ...oldPacking_oldSid.tableData.filter(i => i.skuName !== oldSkuName)
        );
        newPacking_oldSid.rule = oldPacking_oldSid.rule;
        console.log("oldPacking_oldSid :>> ", oldPacking_oldSid);
        await this.changePackingNum(
          oldPacking_newSid.filterData,
          await this.changePackingNum(
            oldPacking_oldSid.filterData,
            newPacking_oldSid.filterData
          )
        );

        await this.changePackingNum(
          oldPacking_oldSid.filterData,
          newPacking_newSid.filterData
        );
        const t = oldPacking_oldSid.tableData.filter(
          i => i.skuName === oldSkuName
        );
        for (const j of t) {
          j.shipmentId = newTarget.shipmentId;
          j.cartonNo =
            newTarget.shipmentId +
            j.cartonNo.slice(j.cartonNo.lastIndexOf("U"));
        }
        console.log("oldPacking_newSid :>> ", oldPacking_newSid);
        // 原有的数据，+ 新增的数据
        newPacking_newSid.tableData.push(...oldPacking_newSid.tableData, ...t);
        newPacking_newSid.rule = oldPacking_newSid.rule;

        await this.changePackingNum(
          oldPacking_newSid.filterData,
          newPacking_newSid.filterData
        );
      } else if (oldSidList.length > 1 && newSidList.length === 0) {
        console.log(
          "-----------修改前不存在新SID数据，修改后存在旧SID数据-------------"
        );

        await this.changePackingNum(
          oldPacking_oldSid.filterData,
          newPacking_oldSid.filterData
        );
        newPacking_oldSid.rule = oldPacking_oldSid.rule;
        newPacking_oldSid.tableData = oldTarget.tableData.filter(
          x => x.skuName !== oldSkuName
        );
        newPacking_oldSid.filterData = oldTarget.filterData.filter(
          x => x.skuName !== oldSkuName
        );

        const t = oldPacking_oldSid.tableData.filter(
          i => i.skuName === oldSkuName
        );
        for (const j of t) {
          j.shipmentId = newTarget.shipmentId;
          j.cartonNo =
            newTarget.shipmentId +
            j.cartonNo.slice(j.cartonNo.lastIndexOf("U"));
        }
        newTarget.tableData.push(...t);
        await this.changePackingNum(
          oldPacking_oldSid.filterData,
          newTarget.filterData
        );
        console.log("newTarget :>> ", newTarget);
      } else if (oldSidList.length === 1 && newSidList.length > 0) {
        console.log(
          "------------修改前存在新SID数据，修改后不存在旧SID数据------------"
        );
        // 旧数据没有其他相同shipmentID数据，有修改后shipmentID数据
        // 原有的数据，+ 新增的数据
        const t = oldPacking_oldSid.tableData;
        for (const j of t) {
          j.shipmentId = newTarget.shipmentId;
          j.cartonNo =
            newTarget.shipmentId +
            j.cartonNo.slice(j.cartonNo.lastIndexOf("U"));
        }

        newPacking_newSid.tableData.push(...oldPacking_newSid.tableData, ...t);
        newPacking_newSid.rule = oldPacking_newSid.rule;

        //
        await this.changePackingNum(
          oldPacking_newSid.filterData,
          await this.changePackingNum(
            oldPacking_oldSid.filterData,
            newPacking_newSid.filterData
          )
        );
      } else if (oldSidList.length === 1 && newSidList.length === 0) {
        console.log(
          "------------修改前不存在新SID数据，修改后不存在旧SID数据-------------"
        );
        // 旧数据没有其他相同shipmentID数据，且没有有修改后shipmentID数据
        const t = oldPacking_oldSid.tableData;
        for (const j of t) {
          j.shipmentId = newTarget.shipmentId;
          j.cartonNo =
            newTarget.shipmentId +
            j.cartonNo.slice(j.cartonNo.lastIndexOf("U"));
        }
        newTarget.tableData.push(...t);
        await this.changePackingNum(
          oldPacking_oldSid.filterData,
          newTarget.filterData
        );
      }
      // console.log('newPacking_newSid :>> ', newPacking_newSid)
      // console.log('newPacking_oldSid :>> ', newPacking_oldSid)
      newPacking_newSid.tableData = this.deduplication(
        newPacking_newSid.tableData
      );
      if (newPacking_oldSid) {
        newPacking_oldSid.tableData = this.deduplication(
          newPacking_oldSid.tableData
        );
        await getSpanArr(newPacking_oldSid);
      }

      return filteredData;
    },
    async changeSkuName(params) {
      /**
       * 修改skuName
       * 1.判断修改前的skuName与修改后的skuName ,同shipmentID 中除了自身之外是否存在相同skuName
       * 2.改前无，改后无   转移数据
       * 3.改前无，改后有   转移，合并数据
       * 4.改前有，改后无   转移，分离数据
       * 5.改前有，改后有   转移，合并数据
       */
      const {
        newTarget,
        oldTarget,
        oldSkuName,
        row,
        newSkuName,
        oldData
      } = params;
      const repeatList = [];
      this.invoiceInfoData.oldTableData.forEach((e, i) => {
        if (i !== row && e.shipmentId === oldTarget.shipmentId) {
          repeatList.push(e);
        }
      });

      console.log("repeatList", repeatList);

      const beforeName = repeatList.find(x => x.sku === oldSkuName);
      const afterName = repeatList.find(x => x.sku === newSkuName);
      console.log(
        "%cbeforeName: ",
        "color: #fff; background: pink;",
        beforeName
      );
      console.log("%cafterName: ", "color: #fff; background: pink;", afterName);

      if (!beforeName && !afterName) {
        // TODO
        console.log("newSkuName :>> ", newSkuName);
        // 改前无，改后无   转移数据
        for (const i of oldTarget.filterData) {
          if (i.skuName === oldSkuName) {
            i.skuName = newSkuName;
          }
        }
        for (const i of oldTarget.tableData) {
          if (i.skuName === oldSkuName) {
            i.skuName = newSkuName;
          }
        }

        newTarget.filterData = oldTarget.filterData;
        newTarget.spanArr = oldTarget.spanArr;
        newTarget.tableData = oldTarget.tableData;
      } else if (!beforeName && afterName) {
        // 改前无，改后有   转移，合并数据
        console.log("改前无，改后有   转移，合并数据 :>> ");
        const targetPacking = oldData.find(
          i => i.shipmentId === afterName.shipmentId
        );

        if (targetPacking.tableData.length === 0) return newTarget;
        console.log("targetPacking :>> ", targetPacking);

        const oldSku = this.invoiceInfoData.oldTableData[row].sku;
        const sku = this.invoiceInfoData.tableData[row].sku;
        for (const i of targetPacking.filterData) {
          if (oldSku && i.skuName === oldSku) {
            i.skuName = sku;
          } else {
            i.skuName = sku;
          }
        }

        for (const i of targetPacking.tableData) {
          if (oldSku && i.skuName === oldSku) {
            i.skuName = sku;
          } else {
            i.skuName = sku;
          }
        }
        newTarget.filterData = await this.changePackingNum(
          targetPacking.filterData,
          newTarget.filterData
        );

        newTarget.spanArr = targetPacking.spanArr;
        newTarget.tableData = this.deduplication(targetPacking.tableData);
      } else if (beforeName && !afterName) {
        // TODO
        console.log("改前有，改后无    转移，合并数据 :>> ");
        // 改前有，改后无   转移，分离数据
      } else if (beforeName && afterName) {
        // TODO
        console.log("改前有，改后有   转移，合并数据 :>> ");
        // 改前有，改后有   转移，合并数据
      }

      return newTarget;
    },
    // 重复数据相加
    deduplication(data) {
      const d = data.reduce((pVal, cVal) => {
        const target = pVal.find(
          x =>
            x.cartonNo === cVal.cartonNo &&
            x.skuName === cVal.skuName &&
            x.declareNameCn === cVal.declareNameCn
        );
        if (target) {
          console.log("target.skuNum :>> ", target.skuNum);
          console.log("cVal.skuNum :>> ", cVal.skuNum);
          // 接收已装箱值，其他不改变
          target.skuNum += cVal.skuNum;
        } else {
          pVal.push(cVal);
        }
        return pVal;
      }, []);

      return d;
    },
    //
    changePackingNum(data, data2) {
      data.reduce((pVal, cVal) => {
        const target = pVal.find(x => x.skuName === cVal.skuName);
        if (target) {
          // 接收已装箱值，其他不改变
          target.packingNum =
            parseInt(cVal.packingNum) + parseInt(target.packingNum);
        }
        return pVal;
      }, data2);
      return data2;
    },

    findSku(data, name) {
      const flag = data.filterData.find(x => x.skuName === name);
      return !!flag;
    },
    checkSku(row, data) {
      const list = [];
      data.forEach((i, index) => {
        if (i[0] === data[row][0] && i[2] === data[row][2]) {
          list.push({
            index
          });
        }
      });

      return list;
    },

    setHeader() {
      let headerList = [];
      if (this.isJapan) {
        headerList = colHeaders.concat(JapanLineHeader);
      } else {
        headerList = colHeaders.concat(otherHeader);
      }
      return headerList;
    },
    coverRenderer(instance, td, row, col, prop, value, cellProperties) {
      const escaped = Handsontable.helper.stringify(value);
      if (
        escaped.indexOf("http") === 0 ||
        escaped.lastIndexOf(".webp") > -1 ||
        escaped.lastIndexOf(".WEBP") > -1 ||
        escaped.lastIndexOf(".bmp") > -1 ||
        escaped.lastIndexOf(".BMP") > -1 ||
        escaped.lastIndexOf(".jpeg") > -1 ||
        escaped.lastIndexOf(".JPEG") > -1 ||
        escaped.lastIndexOf(".jpg") > -1 ||
        escaped.lastIndexOf(".png") > -1 ||
        escaped.lastIndexOf(".JPG") > -1 ||
        escaped.lastIndexOf(".PNG") > -1
      ) {
        const img = document.createElement("img");
        if (value.indexOf("http") > -1) {
          img.setAttribute("src", value);
        } else {
          img.setAttribute("src", constant.FILE_SERVER + value);
        }
        img.setAttribute("class", "hasImg");
        img.onclick = params => {
          this.showUploadImg = true;
          this.ruleForm.coverUrl = img.src;
        };
        Handsontable.dom.addEvent(img, "mousedown", function(event) {
          event.preventDefault();
        });

        Handsontable.dom.empty(td);
        td.appendChild(img);
        td.childNodes[0].style = "width:50px;";
      } else {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        const d = document.createElement("span");
        d.innerHTML = "上传图片";

        d.onclick = params => {
          this.showUploadImg = true;
        };
        td.setAttribute("class", "td-center");
        td.appendChild(d);
      }

      return td;
    },
    // 改变目的仓库
    changeChannelForm() {
      // console.log(
      //   'this.channelFormLeft.purposeWarehouseType :>> ',
      //   this.channelFormLeft.purposeWarehouseType
      // )
      if (this.channelFormLeft.purposeWarehouseType === 100) {
        this.$set(
          this.hotSettings.colHeaders,
          0,
          '<span name="shipmentId">Shipment ID</span>'
        );
        this.$set(
          this.hotSettings.colHeaders,
          1,
          '<span name="shipmentId">Reference ID</span>'
        );
        this.$refs.hotTable.hotInstance.updateSettings(this.hotSettings);
        // this.changeHandsontable({ changeFba: true })
      } else {
        this.$set(
          this.hotSettings.colHeaders,
          0,
          '<span class="noRedTitle" name="shipmentId">Shipment ID</span>'
        );
        this.$set(
          this.hotSettings.colHeaders,
          1,
          '<span class="noRedTitle" name="shipmentId">Reference ID</span>'
        );
        // this.changeHandsontable({ changeFba: true })
      }
    },
    hasClass(elem, cls) {
      cls = cls || "";
      if (cls.replace(/\s/g, "").length === 0) return false; // 当cls没有参数时，返回false
      return new RegExp(" " + cls + " ").test(" " + elem.className + " ");
    },
    resetInvoice() {
      this.$set(this.invoiceInfoData, "tableData", [
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {},
        {}
      ]);

      this.$set(this.invoiceInfoData, "oldPackingInfo", []);
      this.$set(this.invoiceInfoData, "oldTableData", []);
      // 同步更新
      if (this.channelFormLeft.shippingWay !== "99") {
        this.$parent.packingInfo = [];
      }
    },

    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },

    addEmptyData() {
      this.invoiceInfoData.tableData.push({});
    },
    cancelChangeImg() {
      this.ruleForm.coverUrl = "";
      this.showUploadImg = false;
    },
    enterImg() {
      this.showUploadImg = false;
      // console.log(this.coords)
      // console.log(
      //   this.invoiceInfoData.tableData[this.coords.row][this.coords.col]
      // )
      this.invoiceInfoData.tableData[this.coords.row][
        this.coords.col
      ] = this.ruleForm.coverUrl;
      this.ruleForm.coverUrl = "";
    },
    isNoEmptyObject(target) {
      const type = typeof target;
      return (
        target !== null && type === "object" && Object.keys(target).length > 0
      );
    },

    imagePreview: function(file) {
      var self = this;
      // 定义一个文件阅读器
      var reader = new FileReader();
      // 文件装载后将其显示在图片预览里
      reader.onload = function(e) {
        // 将bade64位图片保存至数组里供上面图片显示
        self.ruleForm.coverUrl = e.target.result;
      };
      reader.readAsDataURL(file);
      // console.log(111)
    },
    // 根据国家修改币种
    changeDeclareValueCurrency() {
      const n = this.channelFormLeft.countryId;

      if (!n) return;
      const currencyMap = { USD: "USD" };
      // this.invoiceInfoData.declareValueCurrency = "USD";
      // if (n.indexOf('加拿大') > -1) {
      if (n == 332) {
        currencyMap["CAD"] = "CAD";
      } else if (n == 330) {
        currencyMap["GBP"] = "GBP";
        currencyMap["EUR"] = "EUR";
      } else if (n == 339) {
        currencyMap["AUD"] = "AUD";
      } else if (n == 493) {
        currencyMap["SGD"] = "SGD";
      } else if (n == 335 || n == 331 || n == 336 || n == 334) {
        currencyMap["EUR"] = "EUR";
      }

      if (n == 333) {
        currencyMap["JPY"] = "JPY";
        if (this.createTpye !== "OrderToExpressDelivery") {
          delete currencyMap["USD"];
          // this.invoiceInfoData.declareValueCurrency = "JPY";
        }
      }

      this.currencyMap = currencyMap;
    },
    buildColumns(isJP) {
      const _this = this;
      let defaultColumns = [
        {
          data: "shipmentId", // 指定所指列
          width: 100,
          allowEmpty: false,
          type: "text" // 类型
        },
        {
          data: "referenceId",
          allowEmpty: false,
          width: 90,
          type: "text"
        },
        {
          data: "sku",
          allowEmpty: false,
          width: 120,
          type: "autocomplete",
          source: async function(query, process) {
            if (_this.timer2) {
              clearTimeout(_this.timer2);
            }
            _this.timer2 = setTimeout(() => {
              console.log("query :>> ", query);
              ajax("querySkuInfo", {
                currency: _this.channelFormLeft.declareValueCurrency,
                countryId: _this.channelFormLeft.countryId,
                cuser: _this.channelFormLeft.customerId,
                sku: query
              }).then(res => {
                const skuArrays = res; // 检索后SKU信息集合
                console.log("skuArrays :>> ", skuArrays);
                if (skuArrays) {
                  _this.selectSkuList = skuArrays;
                  const skuCollection = []; // 存储搜索后的SKU集合
                  // selectSku = skuArrays // 将SKU信息赋值给全局变量
                  for (let i = 0; i < skuArrays.length; i++) {
                    const sku = skuArrays[i].sku;
                    if (sku) {
                      skuCollection.push(sku);
                    }
                  }
                  console.log("skuCollection :>> ", skuCollection);
                  process(skuCollection);
                }
              });
            }, 800);
          },
          strict: false
          // renderer: skuCellRenderer
        },

        {
          data: "declareNameEn",
          // allowEmpty: false,
          width: 65,
          type: "text",
          validator: function(v, callback) {
            const reg = new RegExp(
              "([\u4E00-\u9FFF]|[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b\uff01\u3010\u3011\uffe5])+",
              "g"
            );
            if (reg.test(v)) {
              callback(false);
              _this.$message.error("请勿包含中文字符");
            } else {
              callback(true);
            }
          }
        },
        {
          data: "declareNameCn",
          allowEmpty: false,
          width: 65,
          type: "text"
        },
        {
          data: "brand",
          allowEmpty: false,
          width: 55,
          type: "text"
        },
        {
          data: "material",
          allowEmpty: false,
          width: 55,
          type: "text"
        },
        {
          data: "purpose",
          allowEmpty: false,
          width: 55,
          type: "text"
        },
        {
          data: "customsCode",
          allowEmpty: false,
          width: 80,
          type: "text"
        },
        {
          data: "customsClearanceCode",
          allowEmpty: false,
          width: 80,
          type: "text"
        },
        {
          data: "asin",
          width: 75,
          type: "text"
        },
        {
          data: "isCharged",
          type: "text",
          width: 55
        },
        {
          data: "model",
          allowEmpty: false,
          type: "text"
        },
        {
          data: "num",
          allowEmpty: false,
          type: "numeric",
          numericFormat: {
            pattern: "0"
          }
        },
        {
          data: "measurementUnit", // 单位
          allowEmpty: false,
          type: "dropdown",
          source: this.skuUnit
        },
        {
          data: "perSuitNum", //
          type: "numeric",
          numericFormat: {
            pattern: "0"
          }
        },
        {
          data: "purchasingPrice",
          allowEmpty: false,
          type: "numeric",
          numericFormat: {
            pattern: "0.00"
          }
        },
        {
          data: "declareValue",
          allowEmpty: false,
          type: "numeric",
          numericFormat: {
            pattern: "0.00"
          }
        },
        {
          allowEmpty: false,
          // readOnly: true,
          data: "imgUrl",
          renderer: this.coverRenderer
        }
      ];
      // 判断是否日本线
      if (isJP) {
        defaultColumns = [
          {
            data: "shipmentId", // 指定所指列
            width: 100,
            type: "text" // 类型
          },
          {
            data: "referenceId",
            width: 90,
            type: "text"
          },
          {
            data: "sku",
            width: 120,
            type: "autocomplete",
            source: async function(query, process) {
              if (_this.timer2) {
                clearTimeout(_this.timer2);
              }
              _this.timer2 = setTimeout(() => {
                console.log("query :>> ", query);
                ajax("querySkuInfo", {
                  currency: _this.channelFormLeft.declareValueCurrency,
                  countryId: _this.channelFormLeft.countryId,
                  cuser: _this.channelFormLeft.customerId,
                  sku: query
                }).then(res => {
                  const skuArrays = res; // 检索后SKU信息集合
                  console.log("skuArrays :>> ", skuArrays);
                  if (skuArrays) {
                    _this.selectSkuList = skuArrays;
                    const skuCollection = []; // 存储搜索后的SKU集合
                    // selectSku = skuArrays // 将SKU信息赋值给全局变量
                    for (let i = 0; i < skuArrays.length; i++) {
                      const sku = skuArrays[i].sku;
                      if (sku) {
                        skuCollection.push(sku);
                      }
                    }
                    console.log("skuCollection :>> ", skuCollection);
                    process(skuCollection);
                  }
                });
              }, 800);
            },
            strict: true,
            renderer: this.skuCellRenderer
          },
          {
            data: "declareNameEn",
            // allowEmpty: false,
            width: 65,
            type: "text",
            validator: function(v, callback) {
              const reg = new RegExp(
                "([\u4E00-\u9FFF]|[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b\uff01\u3010\u3011\uffe5])+",
                "g"
              );

              if (reg.test(v)) {
                callback(false);
                _this.$message.error("请勿包含中文字符");
              } else {
                callback(true);
              }
            }
          },
          {
            data: "declareNameCn",
            allowEmpty: false,
            width: 65,
            type: "text"
          },
          {
            data: "brand",
            allowEmpty: false,
            width: 55,
            type: "text"
          },
          {
            data: "material",
            allowEmpty: false,
            width: 55,
            type: "text"
          },
          {
            data: "purpose",
            allowEmpty: false,
            width: 55,
            type: "text"
          },
          {
            data: "customsCode",
            allowEmpty: false,
            width: 60,
            type: "text"
          },
          {
            data: "customsClearanceCode",
            allowEmpty: false,
            width: 60,
            type: "text"
          },
          {
            data: "asin",
            width: 75,
            type: "text"
          },

          {
            data: "isCharged",
            type: "text",
            width: 55
          },
          {
            data: "model",
            allowEmpty: false,
            type: "text"
          },
          {
            data: "num",
            allowEmpty: false,
            type: "numeric",
            numericFormat: {
              pattern: "0"
            }
          },
          {
            data: "measurementUnit", // 单位
            allowEmpty: false,
            type: "dropdown",
            source: this.skuUnit
          },
          {
            data: "perSuitNum", //
            type: "numeric",
            numericFormat: {
              pattern: "0"
            }
          },
          {
            data: "fnSku",
            width: 75,
            type: "text",
            validator: function(v, callback) {
              if (v.length > 10) {
                callback(false);
                _this.$message.error("FNSKU限制10位");
              } else {
                callback(true);
              }
            }
          },
          {
            data: "purchasingPrice", // 采购单价
            type: "numeric",
            numericFormat: {
              pattern: "0.00"
            }
          },
          {
            data: "declareValue",
            type: "numeric", // ASIN售价
            numericFormat: {
              pattern: "0.00"
            }
          },
          {
            data: "distributionMaterialCount",
            type: "numeric", // 配送料
            numericFormat: {
              pattern: "0"
            }
          },
          {
            data: "productLotCount",
            type: "numeric", // 出品手数料
            numericFormat: {
              pattern: "0"
            }
          },
          {
            data: "imgUrl",
            renderer: this.coverRenderer
            // readOnly: true
          },
          {
            data: "sellpriceScreenshot",
            // readOnly: true,
            renderer: this.coverRenderer
          },
          {
            data: "incomeScreenshot",
            // readOnly: true,
            renderer: this.coverRenderer
          }
        ];
      }
      return defaultColumns;
    }
  }
};
</script>

<style scoped>
/* .hot-table >>> .el-card__header {
  padding: 6px 20px;
} */
.el-card__header {
  padding: 6px 20px;
}
.handsontable >>> th {
  color: red;
}
.handsontable >>> .noRedTitle {
  color: #222;
}
.handsontable >>> .td-center {
  text-align: center; /*设置水平居中*/
  vertical-align: middle; /*设置垂直bai居中*/
}
.upload-Invoice-dialog >>> .el-dialog__body {
  padding-top: 10px;
}
</style>
<style lang="scss" scoped>
.hot-table {
  position: relative;

  .head-main {
    .head-btn {
      display: inline-block;
      width: 140px;
      height: 26px;
      text-align: center;
      line-height: 26px;
      color: #51abde;
      border: 1px solid #51abde;
      border-radius: 4px;

      cursor: pointer;
    }
    .head-btn-tips {
      color: #fbb64e;
    }
  }

  .el-upload {
    width: 100%;
    .el-upload-dragger {
      width: 100%;
    }
  }
  .tips-a {
    // display: none;
    position: absolute;
    top: 70px;
    right: 13%;
    z-index: 1001;
    background: #fff;
    // border: 1px solid #ccc;
    padding: 10px;
    border-radius: 10px;
    line-height: 2;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
    &::before {
      display: block;
      content: "";
      border-width: 8px 8px 8px 8px;
      border-style: solid;
      border-color: transparent transparent #fff transparent;

      /* 定位 */
      position: absolute;
      right: 10%;
      top: -16px;
    }
  }
  .tips-b {
    right: 7%;
  }
  .isUpload {
    text-align: center;
    color: cornflowerblue;
    cursor: pointer;
    &:hover .upload-text {
      text-decoration: underline;
      color: red;
    }
  }
  .upload-tips {
    font-size: 18px;
    color: #ccc;
  }

  .down-btn {
    margin-bottom: 10px;
    a {
      color: red;
      padding: 8px;
      &:hover {
        text-decoration: underline;
      }
    }
  }
  .upload-Invoice-dialog {
    // position: relative;
    .Invoice-dialog-tips-icon {
      position: absolute;
      top: 15.4%;
      left: 0;
      .icon-question {
        font-size: 26px;
      }
    }
  }
}
</style>
<style lang="scss">
.hot-table {
  .el-upload {
    width: 100%;
    .el-upload-dragger {
      width: 100%;
    }
  }
  .upload-img {
    height: calc(100% - 46px);
    .el-upload {
      width: 100%;
      height: 100%;
      .el-upload-dragger {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.hasImg img {
  width: 26px !important;
  height: 26px;
}
.handsontable th {
  background: #fff;
  color: #2c3e50;
  text-align: left;
  font-weight: bold;
}

.el-card__body {
  color: #606266;
}
.handsontable th:first-child,
.handsontable th:nth-child(2),
.handsontable td:first-of-type,
.handsontable tr th,
.handsontable tr td,
.handsontable tr:first-child th,
.handsontable tr:first-child td {
  border-color: #ebeef5;
}
</style>
